Skip to content

Queries returning duplicate column names fail with ArrowInvalid: Can't unify schema with duplicate field names since 4.2.6 (#989) - #995

Merged
mehmetcankurt merged 4 commits into
mainfrom
ai/issue-989
Oct 23, 2026
Merged

mehmetcankurt merged 4 commits into
mainfrom
ai/issue-989

Conversation

@peco-engineer-bot

Copy link
Copy Markdown
Contributor

Summary

Automated fix for #989 — Queries returning duplicate column names fail with ArrowInvalid: Can't unify schema with duplicate field names since 4.2.6.

Fixed _concat_arrow_tables in src/databricks/sql/utils.py to concatenate chunks without schema promotion when all chunk schemas are equal, avoiding Arrow's schema unification which rejects duplicate field names (GH #989); promotion is retained only when schemas actually differ (the GH #418 nullability case). Verified green via a live-warehouse e2e test asserting duplicate-named columns survive fetchall_arrow()/fetchall()/fetchone(), plus a unit test on the concat path.

Root cause & plan

Root cause: src/databricks/sql/utils.py::_concat_arrow_tables unconditionally calls pyarrow.concat_tables(table_chunks, promote_options="default") (falling back to promote=True). Arrow's schema unification, triggered by any promote option, raises "ArrowInvalid: Can't unify schema with duplicate field names" — even for a single chunk where no promotion is needed. Every Arrow fetch on the Thrift backend routes through concat_table_chunks -> _concat_arrow_tables, so any query whose result has two columns with the same name (e.g. SELECT 1 AS a, 2 AS a, or SELECT * FROM a JOIN b with shared column names) fails on fetchall()/fetchone()/fetchall_arrow(). This regressed in 4.2.6 (PRs #751/#814 for #418); 4.2.5 returned Row(a=1, a=2) correctly. The connector otherwise supports duplicate names (Row docstring, _convert_arrow_table rename logic, unit test test_duplicate_column_names which only exercises _convert_arrow_table and never the concat path).
Files: src/databricks/sql/utils.py, tests/e2e/test_driver.py
Planned coverage:

  • E2E against the live warehouse: cursor.execute("SELECT 1 AS a, 2 AS a") then fetchall_arrow() returns a pyarrow.Table with column_names == ['a','a'], column(0)==[1], column(1)==[2]; fetchall() returns one row with values [1,2]; fetchone() returns a row with values [1,2]. Fails today with ArrowInvalid on the concat step; passes after the fix. Thrift backend (default) since the issue and the concat path are Thrift-specific. (Duplicate column names must survive Arrow fetch (fetchall_arrow / fetchall / fetchone) through concat_table_chunks)

Files changed

  • tests/e2e/test_driver.py
  • src/databricks/sql/utils.py
  • tests/unit/test_util.py

Test plan

  • tests/e2e/test_driver.py::TestPySQLCoreSuite::test_duplicate_column_names_survive_arrow_fetch — fails (red) against the original code, passes (green) after the fix
  • tests/unit/test_util.py::TestUtils::test_concat_table_chunks_duplicate_column_names — fails (red) against the original code, passes (green) after the fix

🤖 Generated by engineer-bot (bug-fix flow) — review before merge.

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — the fix correctly short-circuits to a non-promoting concat_tables when all chunk schemas are equal, which is exactly what's needed to avoid Arrow's duplicate-field-name unification error, and the empty-list/single-chunk cases are safe via the existing guard in concat_table_chunks. One low-severity note about a remaining edge (duplicate names + genuinely differing schemas still hit the promote path). Unit + e2e coverage added.

Comment thread src/databricks/sql/utils.py
peco-engineer-bot Bot added a commit that referenced this pull request Oct 21, 2026
Addresses:
  - #4341406782 at src/databricks/sql/utils.py:940

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — the fix correctly short-circuits to unpromoted concat_tables when all chunk schemas are equal (handles the single-chunk and duplicate-name cases) while preserving the GH #418 promotion path when they differ, and the documented known-limitation is honest. One low note: the new e2e test lacks the @skipUnless(pysql_supports_arrow()) guard its sibling arrow tests use.

Comment thread tests/e2e/test_driver.py
peco-engineer-bot Bot added a commit that referenced this pull request Oct 21, 2026
Addresses:
  - #4341457400 at tests/e2e/test_driver.py:456

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

peco-engineer-bot[bot] and others added 4 commits October 23, 2026 21:09
…'t unify schema with duplicate field names` since 4.2.6 (#989)

Signed-off-by: peco-engineer-bot[bot] <3815206+peco-engineer-bot[bot]@users.noreply.github.com>
Addresses:
  - #4341406782 at src/databricks/sql/utils.py:940

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Addresses:
  - #4341457400 at tests/e2e/test_driver.py:456

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
The non-pyarrow unit test jobs import pyarrow as None, so the new test
failed with AttributeError instead of being skipped like its neighbors.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Mehmet Can Kurt <mehmet.cankurt@databricks.com>

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

@mehmetcankurt
mehmetcankurt added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 0794565 Oct 23, 2026
50 checks passed

This branch was successfully deployed

1 active deployment
azure-prod — e45ceace Deployed Oct 23, 2026 by mehmetcankurt via review #406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engineer-bot Maintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants